package joomz;

import java.util.List;
import javax.script.Bindings;


public class Location
    extends Abstract
    implements Enumerated.Member
{
    public final static Enumerated<Location> Set = new Enumerated<Location>();

    public final static Location Dereference(String id){
        Location re = Set.forName(id);
        if (null != re)
            return re;
        else {
            re = new Location();
            re.setId(id);
            Set.register(re);
            return re;
        }
    }


    public Location(){
        super();
    }


    public void init(Bindings bindings){
        Set.register(this);
        super.init(bindings);
    }
    public boolean isValid(){
        if (null != this.id && (!this.getActions().isEmpty()) && (!this.getObjects().isEmpty())){
            Actor move = Actor.Set.forName("move");
            if (null != move){
                for (Action action : this.actions){
                    if (move == action.getActor()){
                        if (null == action.getDir())
                            throw new Game.Invalid("Location '"+this.getId()+"' Action '"+action.getId()+"' type 'move' missing 'dir'.");
                    }
                }
            }
            return true;
        }
        else
            throw new Game.Invalid("Location '"+this.getId()+"' missing ID or ACTIONS or OBJECTS.");
    }
}
